Twitching is common in dogs and cats during their sleep. It can be harmless and relates to the different stages of sleep they could be experiencing. So if it's happening on the odd occasion for short periods of time, it doesn't sound like it's anything that can bring harm to your dog throughout their life.
However, it is worth noting that if your dog is experiencing this twitching consistently for longer than 5 minutes at a time, it's worth getting a check up with your local vet to find out whether they are actually experiencing a form of epilepsy.
All the best,