fix reproducibility issue for similarity and distance matrices

The class ColorSet assumes that the call to decrementReferences
is done after the call to incrementReferences. If decrementReferences
occurs before incrementReferences, in some cases the virtual color
handle will reach 0 references after the decrementReferences call and
therefore will be purged. But this is a problem if the new and old
virtual color handles are the same.

Other changes are also included in the patch.

Link: https://github.com/sebhtml/ray/issues/216
Signed-off-by: Sébastien Boisvert <sebastien.boisvert.3@ulaval.ca>