Criterion of the hydrodynamic stability of a layer of a heavy fluid over the light one in a geothermal reservoir