ENH: speed-up ndimage.filters.min(max)imum_filter1d

The current implementation of min(max)imum_filter1d rescans the full filter
window at every step, leading to an O(n*m) complexity, n being the size of
the image, and m of the filter.
This PR changes the computation algorithm, keeping track of the min(max)imum
value, and its offset from the current position. This allows to compute the
min(max)imum by making a single compare of the next value in the image against
the min(max)imum, and checking that the min(max)imum is still within the filter
window. This leads to an expected O(n) average performance, although the worst
case is still O(n*m).

The worst case happens for strictly inc(dec)reasing sequences of values, and in
this case the performance is actually worse than the original, because of the
overhead of computing the min(max)imum offset.
Merge pull request #3517 from jaimefrio/minmax-filter

ENH: speed-up ndimage.filters.min(max)imum_filter1d