Nuclear medium effects on invariant mass spectra of hadrons decaying in nuclei