[ftools] Fix distance matrix (Fix #8103)