function [merge idx] = mergeClusters(pts1, pts2, CENT_THRESH, PT_THRESH, CORR_THRESH)
% Decide whether to merge two clusters of points

% Quickly compare centers
if norm(median(pts1)-median(pts2)) > CENT_THRESH
   merge = false; return;
end

% Compute point pairwise euclidean distances
dists = repmat(sum(pts1.^2,2),1,size(pts2,1)) - 2*pts1*pts2' + repmat(sum(pts2.^2,2),1,size(pts1,1))';

[dists idx] = min(dists,[],2);
idx(dists > PT_THRESH) = 0;
merge = nnz(dists < PT_THRESH)/size(dists,1) > CORR_THRESH;

