Self-improving properties of inequalities of Poincaré type on measure spaces and applications