Better management of frame idx

Signed-off-by: Carlo Caione <carlo.caione@gmail.com>