Theory of homogeneous linewidths of impurities in polymers and glasses