This story is from Katha Upanishad (Kathopanishad).
Transmutation of Sexual Energy
In a mother’s womb were two babies. One asked the other: “Do you believe in life after delivery?”