[MRG] Refactor CV and grid search

While implementing #2701 I have seen some duplicate code in `grid_search` and `cross_validation`. Before I will implement the rest of issue #2584 I would like to clean that up a little bit.