Measuring and testing homogeneity of distributions by characteristic distance