Automatic Battery Selection Circuit
The following circuit will select the higher of the two input voltages to output. The circuit will work if at least one of the batteries has 3.7V.



simulate this circuit &ndash; Schematic created using CircuitLab
Diodes DM1, 2, 3 and 4 are the body diodes of the M1, 2, 3 and 4 respectively, and are not actual discrete diodes in the circuit.
The purpose of the bypass diodes, D1 and D2, is to ensure that there is a voltage at Vout whenever there is there is a voltage at either V1 or V2, even if this voltage is one or two diode drops below the larger battery voltage. This allows the differential pair consisting of Q1, Q2, R5, R6, and R7 to bootstrap.
The voltage dividers consisting of R1, R2, R3 and R4 provide inputs to the differential pair, which will then &quot;select&quot; the higher voltage, and turn on the MOSFETS for that line. Once the MOSFETS conduct, the bypass diode voltage drop will disappear.
If the batteries are in the 3.7-4.2V range, as they are in this example, M1-M4 should be &quot;logic level&quot; MOSFETs. The lower the threshold voltage the better.
If batteries with voltages significantly different from those in the circuit are used, component values may need to be changed. It the voltages are too low, it may difficult or impossible to get the circuit to work, because discrete MOSFET threshold voltages only go so low.
Current will not back-flow from a battery with higher voltage into the battery with lower voltage, at least in the voltage ranges that I have tested. If the batteries have significantly higher voltage, component values may need to be adjusted to ensure that the region in which both MOSFETS may be conducting is sufficiently narrow.
The circuit may be simulated in CircuitLab.
Here is a sample simulation showing the Output voltage, as well as the gate voltages for the MOSFETS as the V1 voltage varies.