Formation of methane in comet impacts: implications for Earth, Mars, and Titan