Theory of frequency-filtered and time-resolved N-photon correlations