Fixed wrong index in filter algorithm