sort and group cands after cands generation for a node