Query to fetch items at certain interval between them (if it exist)

PS this is a solution as a view

function (doc, meta) {
var iv = doc.length > 0 ? new Date(doc[0].timestamp) : new Date();

for(var n in doc)
{
var e = doc[n];
var tm = new Date(e.timestamp);

if((iv.getTime() + 5 * 60 * 1000) < tm.getTime())
{
  iv = tm;
  emit(null, e);
}

}
}

thanks!