A direct method for the numerical time reversal of waves in a heterogeneous medium