Fix #5181,#4761 - Ftools-Distance Matrix

fix distance matrix k and k-1 issue