Changed sample filtering from average to median, using std::nth_element