function newIDstatus = updateIDstatus(IDstatus,HeadposeWithIDs)

newIDstatus = IDstatus;

ToDelete = [];
for j = 1:length(newIDstatus)
    idstat = newIDstatus{j};
    idstat.Timediff = idstat.Timediff+1;
    %     if idstat.Timediff>30,
    %         idstat.Timediff
    %     end
    if idstat.Timediff>150 % 5s
        ToDelete = [ToDelete,j];
    end
    newIDstatus{j} = idstat;
end

if ~isempty(ToDelete),
    newIDstatus(ToDelete) = [];
end

if ~isempty(HeadposeWithIDs)
    currentIDs = HeadposeWithIDs(4,:);
    
    for i = 1:length(currentIDs),
        update = 0;
        currentid = currentIDs(i);
        for j = 1:length(newIDstatus),
            idstat = newIDstatus{j};
            if idstat.id==currentid,
                update = 1;
                idstat.Timediff = 1;
                idstat.pos = HeadposeWithIDs(1:3,i);
                newIDstatus{j} = idstat;
            end
        end
        
        if update==0, % add it to IDstatus
            idstat.id = currentid;
            idstat.Timediff = 1;
            idstat.pos = HeadposeWithIDs(1:3,i);
            newIDstatus{length(newIDstatus)+1} = idstat;
        end
    end
end



