Density-based clustering of image keypoints
Just for correctness and not for performance reasons:
You nowhere mark any key as being clustered. As a result, keys may be clustered multiple times. In case all keys shall be clustered maximum one time, one may do the following modifications to the code above:

Add a following first line 

clustered[i] = true; 


behind

// add P to cluster c
clusters[c].push_back(keypoints-&gt;at(i));


and a following second line

clustered[neighborPts[j]] = true;


after

clusters[current_cluster].push_back(keypoints-&gt;at(neighborPts[j]));


Concerning the second line, make sure that it is inserted within the if-statement.