You can use the following code to keep the top M keypoints that have the largest response:
bool compareFunction(KeyPoint p1, KeyPoint p2) {return p1.response>p2.response;}
//The function retains the stongest M keypoints in kp
void RetainBestKeypoints(vector<KeyPoint> &kp, int M)
{
vector<KeyPoint> sortedkp;
sort(kp.begin(),kp.end(),compareFunction);
if (kp.size()>M)
kp.erase(kp.begin()+M,kp.end());
}