Refactor the between cluster similarity function.